class Solution:
    def maxProfit(self, prices: list) -> int:
        if len(prices) == 0:
            return 0
        buy_price, earn_list = prices[0], prices[:]
        earn_list[0] = 0
        for i in range(1, len(prices)):
            if prices[i] < buy_price:
                earn_list[i] = 0
                buy_price = prices[i]
            else:
                earn_list[i] = prices[i] - buy_price
        return max(earn_list)


a = Solution()
print(a.maxProfit([7, 1, 5, 3, 6, 4]))
print(a.maxProfit([7, 3, 5, 1, 6, 4]))
print(a.maxProfit([7, 3, 5, 6, 1, 4]))
print(a.maxProfit([7, 6, 4, 3, 1]))
print(a.maxProfit([]))
